package cn.exempale.mscapplication.utils;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.Map;

/**
 * json工具类
 * 使用Gson
 */
public final class JsonUtils {

    public static Gson gson = new Gson();

    /**
     * 实体类 转 map
     *
     * @param object
     * @return
     */
    public static Map<String, String> Obj2Map(Object object) {
        if (gson == null)
            gson = new Gson();
        String jsonString = gson.toJson(object);
        if (jsonString != null) {
            Type type = new TypeToken<Map<String, String>>() {
            }.getType();
            return gson.fromJson(jsonString, type);
        }
        return null;
    }
}
